/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.web.manager.category;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.hutech09.jsale.bsn.ICategoryManager;
import org.hutech09.jsale.bsn.exception.ItemExistsException;
import org.hutech09.jsale.entity.ProductType;

/**
 *
 * @author Nam
 */
@ManagedBean
@RequestScoped
public class ProductTypeCuCtrl {

    @EJB
    private ICategoryManager cm;

    private ProductType productType;

    private String affterApplyPage;

    public ProductType getProductType() {
        return productType;
    }

    public void setProductType(ProductType productType) {
        this.productType = productType;
    }

    public String showCreate(String affterApplyPage) {
        this.affterApplyPage = affterApplyPage;
        return "productTypeCreatePage";
    }

    public String showUpdate(ProductType productType, String affterApplyPage) {
        this.productType = productType;
        this.affterApplyPage = affterApplyPage;
        return "productTypeEditPage";
    }

    public String update() {
        try {
            cm.update(productType);
        } catch (ItemExistsException ex) {
            Logger.getLogger(ProductTypeCuCtrl.class.getName()).log(Level.SEVERE, null, ex);
            return "";
        }
        return affterApplyPage;
    }

    public String create() {
        cm.create(productType);
        return affterApplyPage;
    }

}
